package cn.yudao.mq;


import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;

public class producer {

    public static void main(String[] args) throws Exception {
        // 创建连接对象
        DefaultMQProducer producer = new DefaultMQProducer("sync_producer_group");
        // 连接nameserver
        producer.setNamesrvAddr("127.0.0.1:9876");
        // 启动
        producer.start();
        // 发送信息
        Message message = new Message("sync", "hello", "李多是吾儿".getBytes(StandardCharsets.UTF_8));
        SendResult send = producer.send(message);
        // 打印返回值
        System.out.println(send);
        // 关闭
        producer.shutdown();
    }



}
